// --------------------------------------------------------------------------------------------------------------------- 
// <copyright file="TfsEvent.cs" company="Scrum for Team System">
//   None
// </copyright>
// <summary>
//   Defines the TfsEvent type.
// </summary>
// ---------------------------------------------------------------------------------------------------------------------

namespace ScrumForTeamSystem.EventService.Services
{
    using System;

    using ScrumForTeamSystem.EventService.Infrastructure;
    using ScrumForTeamSystem.EventService.Infrastructure.Enums;
    using ScrumForTeamSystem.EventService.Infrastructure.Interfaces;

    /// <summary>
    /// Defines the TfsEvent type.
    /// </summary>
    internal class TfsEvent : ITfsEvent
    {
        /// <summary>
        /// Instance of the event source
        /// </summary>
        private readonly object eventSource;

        /// <summary>
        /// Instance of the server identity
        /// </summary>
        private readonly TFSIdentity serverIdentity;

        /// <summary>
        /// Instance of the event sate
        /// </summary>
        private TfsEventState tfsEventState;

        /// <summary>
        /// Initializes a new instance of the <see cref="TfsEvent"/> class.
        /// </summary>
        /// <param name="eventSourceObject">The event source object.</param>
        /// <param name="serverIdentity">The server identity.</param>
        public TfsEvent(object eventSourceObject, TFSIdentity serverIdentity)
        {
            this.State = TfsEventState.Created;
            this.eventSource = eventSourceObject;
            this.serverIdentity = serverIdentity;
        }

        /// <summary>
        /// Occurs when [state changed] event raised.
        /// </summary>
        public event EventHandler<TfsEventArgs> StateChanged;

        /// <summary>
        /// Gets EventSource.
        /// </summary>
        /// <value>The event source.</value>
        public object EventSource
        {
            get
            {
                return this.eventSource;
            }
        }

        /// <summary>
        /// Gets EventSourceType.
        /// </summary>
        /// <value>The event source type.</value>
        public Type EventSourceType
        {
            get
            {
                return this.eventSource.GetType();
            }
        }

        /// <summary>
        /// Gets ServerIdentity.
        /// </summary>
        /// <value>The server identity.</value>
        public TFSIdentity ServerIdentity
        {
            get
            {
                return this.serverIdentity;
            }
        }

        /// <summary>
        /// Gets or sets State.
        /// </summary>
        /// <value>The state.</value>
        public TfsEventState State
        {
            get
            {
                return this.tfsEventState;
            }

            set
            {
                if (this.tfsEventState == value)
                {
                    return;
                }

                if (this.StateChanged != null)
                {
                    this.StateChanged(this, new TfsEventArgs(this));
                }

                this.tfsEventState = value;
            }
        }
    }
}